package com.weishi.project.training.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weishi.common.utils.StringUtils;
import com.weishi.project.api.ret.SportsmanPhysicalQualityRet;
import com.weishi.project.api.vo.*;
import com.weishi.project.training.domain.Sportsman;
import com.weishi.project.training.domain.SportsmanPhysicalQuality;
import com.weishi.project.training.mapper.SportsmanMapper;
import com.weishi.project.training.mapper.SportsmanMatchMapper;
import com.weishi.project.training.mapper.SportsmanPhysicalQualityMapper;
import com.weishi.project.training.service.ISportsmanPhysicalQualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.*;

/**
 * sportsmanPhysicalQualityService业务层处理
 */
@Service
public class SportsmanPhysicalQualityServiceImpl extends ServiceImpl<SportsmanPhysicalQualityMapper, SportsmanPhysicalQuality> implements ISportsmanPhysicalQualityService {

    @Autowired
    private SportsmanPhysicalQualityMapper sportsmanPhysicalQualityMapper;

    @Autowired
    private SportsmanMatchMapper sportsmanMatchMapper;

    @Autowired
    private SportsmanMapper sportsmanMapper;


    /**
     * 查询sportsmanPhysicalQuality列表
     */
    @Override
    public List<SportsmanPhysicalQuality> selectSportsmanPhysicalQualityList(SportsmanPhysicalQuality sportsmanPhysicalQuality) {
//        String sportsmanName = sportsmanMatchMapper.queryBySprotsmanId(sportsmanPhysicalQuality.getSportsmanId());
//        sportsmanPhysicalQuality.setSportsmanName(sportsmanName);
        return sportsmanPhysicalQualityMapper.selectSportsmanPhysicalQualityList(sportsmanPhysicalQuality);
    }

    @Override
    public Map<String, List<SportsmanPhysicalQualityRet>> selectMapList(SportsmanPhysicalQuality sportsmanPhysicalQuality) {
        Map<String, List<SportsmanPhysicalQualityRet>> map = new HashMap<>();
        try {
            List<SportsmanPhysicalQuality> list = sportsmanPhysicalQualityMapper.selectSportsmanPhysicalQualityList(sportsmanPhysicalQuality);
            for (SportsmanPhysicalQuality physicalQuality : list) {
                List<SportsmanPhysicalQualityRet> powerList = SportsmanPhysicalQualityRet.getPowerList();
                setSportsmanPhysicalQualityRetValue(powerList, physicalQuality);
                map.put("power", powerList);

                List<SportsmanPhysicalQualityRet> enduranceList = SportsmanPhysicalQualityRet.getEnduranceList();
                setSportsmanPhysicalQualityRetValue(enduranceList, physicalQuality);
                map.put("endurance", enduranceList);

                List<SportsmanPhysicalQualityRet> basicList = SportsmanPhysicalQualityRet.getBasicList();
                setSportsmanPhysicalQualityRetValue(basicList, physicalQuality);
                map.put("basic", basicList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    private void setSportsmanPhysicalQualityRetValue(List<SportsmanPhysicalQualityRet> list, SportsmanPhysicalQuality physicalQuality) {
        try {
            Class clazz = Class.forName("com.weishi.project.training.domain.SportsmanPhysicalQuality");
            for (SportsmanPhysicalQualityRet sportsmanPhysicalQualityRet : list) {
                Field field = clazz.getDeclaredField(sportsmanPhysicalQualityRet.getKey());
                field.setAccessible(true);
                Object fieldVal = field.get(physicalQuality);
                if(fieldVal!=null) sportsmanPhysicalQualityRet.setValue(fieldVal.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public Map<String, List<SportsmanPhysicalQualityRet>> getSportsmanPhysicalQualityBySportsmanId(Integer sportsmanId, boolean isOptimal) {
        SportsmanPhysicalQuality params = new SportsmanPhysicalQuality();
        params.setSportsmanId(sportsmanId);
        List<SportsmanPhysicalQuality> list = sportsmanPhysicalQualityMapper.selectSportsmanPhysicalQualityList(params);
        SportsmanPhysicalQuality temp = new SportsmanPhysicalQuality();
        if (list != null && list.size() > 0) {
            temp = list.get(0);
            if (isOptimal) {
                //获取最优物理属性
                for (SportsmanPhysicalQuality physicalQuality : list) {

                    if(physicalQuality.getOne() > temp.getOne()){
                        temp.setOne(physicalQuality.getOne());
                    }
                    if(physicalQuality.getOneIdeal() > temp.getOneIdeal()){
                        temp.setOneIdeal(physicalQuality.getOneIdeal());
                    }
                    if(physicalQuality.getTwo() > temp.getTwo()){
                        temp.setTwo(physicalQuality.getTwo());
                    }
                    if(physicalQuality.getTwoIdeal() > temp.getTwoIdeal()){
                        temp.setTwoIdeal(physicalQuality.getTwoIdeal());
                    }
                    if(physicalQuality.getThree() > temp.getThree()){
                        temp.setThree(physicalQuality.getThree());
                    }
                    if(physicalQuality.getThreeIdeal() > temp.getThreeIdeal()){
                        temp.setThreeIdeal(physicalQuality.getThreeIdeal());
                    }
                    if(physicalQuality.getFour() > temp.getFour()){
                        temp.setFour(physicalQuality.getFour());
                    }
                    if(physicalQuality.getFourIdeal() > temp.getFourIdeal()){
                        temp.setFourIdeal(physicalQuality.getFourIdeal());
                    }
                    if(physicalQuality.getFive() > temp.getFive()){
                        temp.setFive(physicalQuality.getFive());
                    }
                    if(physicalQuality.getFiveIdeal() > temp.getFiveIdeal()){
                        temp.setFiveIdeal(physicalQuality.getFiveIdeal());
                    }
                    if(physicalQuality.getSix() > temp.getSix()){
                        temp.setSix(physicalQuality.getSix());
                    }
                    if(physicalQuality.getSixIdeal() > temp.getSixIdeal()){
                        temp.setSixIdeal(physicalQuality.getSixIdeal());
                    }
                    if(physicalQuality.getSeven() > temp.getSeven()){
                        temp.setSeven(physicalQuality.getSeven());
                    }
                    if(physicalQuality.getSevenIdeal() > temp.getSevenIdeal()){
                        temp.setSevenIdeal(physicalQuality.getSevenIdeal());
                    }
                    if(physicalQuality.getEight() > temp.getEight()){
                        temp.setEight(physicalQuality.getEight());
                    }
                    if(physicalQuality.getEightIdeal() > temp.getEightIdeal()){
                        temp.setEightIdeal(physicalQuality.getEightIdeal());
                    }
                    if(physicalQuality.getNine() > temp.getNine()){
                        temp.setNine(physicalQuality.getNine());
                    }
                    if(physicalQuality.getNineIdeal() > temp.getNineIdeal()){
                        temp.setNineIdeal(physicalQuality.getNineIdeal());
                    }
                    if(physicalQuality.getTen() > temp.getTen()){
                        temp.setTen(physicalQuality.getTen());
                    }
                    if(physicalQuality.getTenIdeal() > temp.getTenIdeal()){
                        temp.setTenIdeal(physicalQuality.getTenIdeal());
                    }
                    if(physicalQuality.getEleven() > temp.getEleven()){
                        temp.setEleven(physicalQuality.getEleven());
                    }
                    if(physicalQuality.getElevenIdeal() > temp.getElevenIdeal()){
                        temp.setElevenIdeal(physicalQuality.getElevenIdeal());
                    }
                    if(physicalQuality.getTwelve() > temp.getTwelve()){
                        temp.setTwelve(physicalQuality.getTwelve());
                    }
                    if(physicalQuality.getTwelveIdeal() > temp.getTwelveIdeal()){
                        temp.setTwelveIdeal(physicalQuality.getTwelveIdeal());
                    }
                    if(physicalQuality.getThirteen() > temp.getThirteen()){
                        temp.setThirteen(physicalQuality.getThirteen());
                    }
                    if(physicalQuality.getThirteenIdeal() > temp.getThirteenIdeal()){
                        temp.setThirteenIdeal(physicalQuality.getThirteenIdeal());
                    }
                    if(physicalQuality.getFourteen() > temp.getFourteen()){
                        temp.setFourteen(physicalQuality.getFourteen());
                    }
                    if(physicalQuality.getFourteenIdeal() > temp.getFourteenIdeal()){
                        temp.setFourteenIdeal(physicalQuality.getFourteenIdeal());
                    }
                    if(physicalQuality.getFifteen() > temp.getFifteen()){
                        temp.setFifteen(physicalQuality.getFifteen());
                    }
                    if(physicalQuality.getFifteenIdeal() > temp.getFifteenIdeal()){
                        temp.setFifteenIdeal(physicalQuality.getFifteenIdeal());
                    }
                    if(physicalQuality.getSixteen() > temp.getSixteen()){
                        temp.setSixteen(physicalQuality.getSixteen());
                    }
                    if(physicalQuality.getSixteenIdeal() > temp.getSixteenIdeal()){
                        temp.setSixteenIdeal(physicalQuality.getSixteenIdeal());
                    }
                    if(physicalQuality.getEighteen() > temp.getEighteen()){
                        temp.setEighteen(physicalQuality.getEighteen());
                    }
                    if(physicalQuality.getEighteenIdeal() > temp.getEighteenIdeal()){
                        temp.setEighteenIdeal(physicalQuality.getEighteenIdeal());
                    }

                    if (physicalQuality.getBenchPress() > temp.getBenchPress())
                        temp.setBenchPress(physicalQuality.getBenchPress());
                    if (physicalQuality.getBenchPressIdeal() > temp.getBenchPressIdeal())
                        temp.setBenchPressIdeal(physicalQuality.getBenchPressIdeal());
                    if (physicalQuality.getBenchPress25kg3m() > temp.getBenchPress25kg3m())
                        temp.setBenchPress25kg3m(physicalQuality.getBenchPress25kg3m());
                    if (physicalQuality.getBenchPress25kg3mIdeal() > temp.getBenchPress25kg3mIdeal())
                        temp.setBenchPress25kg3mIdeal(physicalQuality.getBenchPress25kg3mIdeal());
                    if (physicalQuality.getHardPull() > temp.getHardPull())
                        temp.setHardPull(physicalQuality.getHardPull());
                    if (physicalQuality.getHardPullIdeal() > temp.getHardPullIdeal())
                        temp.setHardPullIdeal(physicalQuality.getHardPullIdeal());
                    if (physicalQuality.getWola() > temp.getWola()) temp.setWola(physicalQuality.getWola());
                    if (physicalQuality.getWolaIdeal() > temp.getWolaIdeal())
                        temp.setWolaIdeal(physicalQuality.getWolaIdeal());
                    if (physicalQuality.getWola30kg3m() > temp.getWola30kg3m())
                        temp.setWola30kg3m(physicalQuality.getWola30kg3m());
                    if (physicalQuality.getWola30kg3mIdeal() > temp.getWola30kg3mIdeal())
                        temp.setWola30kg3mIdeal(physicalQuality.getWola30kg3mIdeal());
                    if (physicalQuality.getHighTurnover() > temp.getHighTurnover())
                        temp.setHighTurnover(physicalQuality.getHighTurnover());
                    if (physicalQuality.getHighTurnoverIdeal() > temp.getHighTurnoverIdeal())
                        temp.setHighTurnoverIdeal(physicalQuality.getHighTurnoverIdeal());
                    if (physicalQuality.getSquat() > temp.getSquat()) temp.setSquat(physicalQuality.getSquat());
                    if (physicalQuality.getSquatIdeal() > temp.getSquatIdeal())
                        temp.setSquatIdeal(physicalQuality.getSquatIdeal());
                    if (physicalQuality.getPullStomachs3m() > temp.getPullStomachs3m())
                        temp.setPullStomachs3m(physicalQuality.getPullStomachs3m());
                    if (physicalQuality.getPullStomachs3mIdeal() > temp.getPullStomachs3mIdeal())
                        temp.setPullStomachs3mIdeal(physicalQuality.getPullStomachs3mIdeal());
                    if (physicalQuality.getSquat40kg3m() > temp.getSquat40kg3m())
                        temp.setSquat40kg3m(physicalQuality.getSquat40kg3m());
                    if (physicalQuality.getSquat40kg3mIdeal() > temp.getSquat40kg3mIdeal())
                        temp.setSquat40kg3mIdeal(physicalQuality.getSquat40kg3mIdeal());
                    if (physicalQuality.getAbdominalEndurance() > temp.getAbdominalEndurance())
                        temp.setAbdominalEndurance(physicalQuality.getAbdominalEndurance());
                    if (physicalQuality.getAbdominalEnduranceIdeal() > temp.getAbdominalEnduranceIdeal())
                        temp.setAbdominalEnduranceIdeal(physicalQuality.getAbdominalEnduranceIdeal());
                    if (physicalQuality.getPullUp() > temp.getPullUp()) temp.setPullUp(physicalQuality.getPullUp());
                    if (physicalQuality.getPullUpIdeal() > temp.getPullUpIdeal())
                        temp.setPullUpIdeal(physicalQuality.getPullUpIdeal());
                    if (physicalQuality.getStaticElevatedDorsalMuscle() > temp.getStaticElevatedDorsalMuscle())
                        temp.setStaticElevatedDorsalMuscle(physicalQuality.getStaticElevatedDorsalMuscle());
                    if (physicalQuality.getStaticElevatedDorsalMuscleIdeal() > temp.getStaticElevatedDorsalMuscleIdeal())
                        temp.setStaticElevatedDorsalMuscleIdeal(physicalQuality.getStaticElevatedDorsalMuscleIdeal());
                    if (physicalQuality.getBackMuscleEndurance() > temp.getBackMuscleEndurance())
                        temp.setBackMuscleEndurance(physicalQuality.getBackMuscleEndurance());
                    if (physicalQuality.getBackMuscleEnduranceIdeal() > temp.getBackMuscleEnduranceIdeal())
                        temp.setBackMuscleEnduranceIdeal(physicalQuality.getBackMuscleEnduranceIdeal());
                    if (physicalQuality.getVerticalJump() > temp.getVerticalJump())
                        temp.setVerticalJump(physicalQuality.getVerticalJump());
                    if (physicalQuality.getVerticalJumpIdeal() > temp.getVerticalJumpIdeal())
                        temp.setVerticalJumpIdeal(physicalQuality.getVerticalJumpIdeal());
                    if (physicalQuality.getAnteflexion() > temp.getAnteflexion())
                        temp.setAnteflexion(physicalQuality.getAnteflexion());
                    if (physicalQuality.getAnteflexionIdeal() > temp.getAnteflexionIdeal())
                        temp.setAnteflexionIdeal(physicalQuality.getAnteflexionIdeal());
                    if (physicalQuality.getRun30m()>0 && physicalQuality.getRun30m() < temp.getRun30m()) temp.setRun30m(physicalQuality.getRun30m());
                    if (physicalQuality.getRun30mIdeal() > temp.getRun30mIdeal())
                        temp.setRun30mIdeal(physicalQuality.getRun30mIdeal());
                    if (physicalQuality.getRun3000m()>0 && physicalQuality.getRun3000m() < temp.getRun3000m())
                        temp.setRun3000m(physicalQuality.getRun3000m());
                    if (physicalQuality.getRun3000mIdeal() > temp.getRun3000mIdeal())
                        temp.setRun3000mIdeal(physicalQuality.getRun3000mIdeal());
                    if (physicalQuality.getThreeStepJump() > temp.getThreeStepJump())
                        temp.setThreeStepJump(physicalQuality.getThreeStepJump());
                    if (physicalQuality.getThreeStepJumpIdeal() > temp.getThreeStepJumpIdeal())
                        temp.setThreeStepJumpIdeal(physicalQuality.getThreeStepJumpIdeal());
                }
            }
        }
        Map<String, List<SportsmanPhysicalQualityRet>> map = new HashMap<>();
        try {
            List<SportsmanPhysicalQualityRet> powerList = SportsmanPhysicalQualityRet.getPowerList();
            setSportsmanPhysicalQualityRetValue(powerList, temp);
            map.put("power", powerList);

            List<SportsmanPhysicalQualityRet> enduranceList = SportsmanPhysicalQualityRet.getEnduranceList();
            setSportsmanPhysicalQualityRetValue(enduranceList, temp);
            map.put("endurance", enduranceList);

            List<SportsmanPhysicalQualityRet> basicList = SportsmanPhysicalQualityRet.getBasicList();
            setSportsmanPhysicalQualityRetValue(basicList, temp);
            map.put("basic", basicList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public List<RankingVo> getRanking(List<RangkingDetailsParamsVo> rankingParamsVos) {
        List<RankingVo> ret = new ArrayList<>();
        Sportsman sportsman = null;
        for(RangkingDetailsParamsVo paramsVo : rankingParamsVos){
            if(sportsman==null) sportsman = sportsmanMapper.selectById(paramsVo.getSportsmanId());
            paramsVo.setSex(sportsman.getSex());
            paramsVo.setNumType(paramsVo.getNameType());
            List<RangkingDetailsVo> list = sportsmanPhysicalQualityMapper.getRangkingDetailsVo(paramsVo);
            int index=0;
            RankingVo rankingVo = new RankingVo();
            rankingVo.setType(paramsVo.getNumType());
            Map<String,Integer> map = new HashMap<>();
            for(RangkingDetailsVo vo : list){
                if(map.get(vo.getType())==null){
                    index++;
                    map.put(vo.getType(),index);
                }
                if(paramsVo.getSportsmanId()==vo.getSportsmanId()){
                    rankingVo.setRank(index);
                    rankingVo.setValue(vo.getType());
                    break;
                }
            }
            ret.add(rankingVo);
        }
        return ret;
    }

    @Override
    public List<RankingVo> countSportsmanPhysicalQualityBySportsmanIdAndType(List<RankingParamsVo> rankingParamsVos) {
        List<RankingVo> rankingVos = new ArrayList<>();
        int increment = 0;//相同名词的增量
        for (RankingParamsVo rankingParamsVo : rankingParamsVos) {
            Sportsman sportsman = sportsmanMapper.selectById(rankingParamsVo.getSportsmanId());
            Map<String, Object> map = new HashMap<>();
            if (rankingParamsVo.getNameType().equals("benchPress")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countBenchPress(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("benchPress");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("wola")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countWola(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("wola");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("squat")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countSquat(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("squat");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("hardPull")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countHardPull(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("hardPull");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("highTurnover")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countHighTurnover(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("highTurnover");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("benchPress25kg3m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countBenchPress25kg3m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("benchPress25kg3m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("wola30kg3m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countWola30kg3m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("wola30kg3m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("pullStomachs3m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countPullStomachs3m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("pullStomachs3m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("squat40kg3m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countSquat40kg3m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("squat40kg3m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("abdominalEndurance")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countAbdominalEndurance(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("abdominalEndurance");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("pullUp")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countPullUp(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("pullUp");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("staticElevatedDorsalMuscle")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countStaticElevatedDorsalMuscle(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("staticElevatedDorsalMuscle");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("backMuscleEndurance")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countBackMuscleEndurance(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("backMuscleEndurance");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("verticalJump")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countVerticalJump(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("verticalJump");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("anteflexion")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countAnteflexion(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("anteflexion");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("run30m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countRun30m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("run30m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("run3000m")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countRun3000m(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("run3000m");
                rankingVos.add(rankingVo);
            }

            if (rankingParamsVo.getNameType().equals("threeStepJump")) {
                map.put("sex", sportsman.getSex());
                map.put("valueType", rankingParamsVo.getValueType());
                map.put("echelon", rankingParamsVo.getEchelon());
                int count = sportsmanPhysicalQualityMapper.countThreeStepJump(map);
                RankingVo rankingVo = new RankingVo();
                rankingVo.setRank(count + 1);
                rankingVo.setType("threeStepJump");
                rankingVos.add(rankingVo);
            }

        }


        return rankingVos;
    }

    @Override
    public List<RangkingDetailsVo> getRangkingDetailsVo(RangkingDetailsParamsVo rangkingDetailsParamsVo) {
        return sportsmanPhysicalQualityMapper.getRangkingDetailsVo(rangkingDetailsParamsVo);
    }

    @Override
    public List<RangkingDetailsVo> getSportsmanPhysicalQualityHistory(HistoryVo historyVo) {
        if(StringUtils.isNotEmpty(historyVo.getStartTime())){
            historyVo.setStartTime(historyVo.getStartTime() + " 00:00:00");
        }
        if(StringUtils.isNotEmpty(historyVo.getEndTime())){
            historyVo.setEndTime(historyVo.getEndTime() + " 23:59:59");
        }
        return sportsmanPhysicalQualityMapper.getSportsmanPhysicalQualityHistory(historyVo);
    }


    /**
     * 查询运动员姓名集合
     *
     * @return List<Sportsman>
     */
    @Override
    public List<Sportsman> querySportsNameList() {
        return sportsmanPhysicalQualityMapper.querySportsNameList();
    }

    @Override
    public Map<String, List<SportsmanPhysicalQualityRet>> getSportsmanPhysicalQualityById(int sportsmanId) {
        SportsmanPhysicalQuality temp = sportsmanPhysicalQualityMapper.getSportsmanPhysicalQualityById(sportsmanId);
        Map<String, List<SportsmanPhysicalQualityRet>> map = new HashMap<>();
        try {
            List<SportsmanPhysicalQualityRet> powerList = SportsmanPhysicalQualityRet.getPowerList();
            setSportsmanPhysicalQualityRetValue(powerList, temp);
            map.put("power", powerList);

            List<SportsmanPhysicalQualityRet> enduranceList = SportsmanPhysicalQualityRet.getEnduranceList();
            setSportsmanPhysicalQualityRetValue(enduranceList, temp);
            map.put("endurance", enduranceList);

            List<SportsmanPhysicalQualityRet> basicList = SportsmanPhysicalQualityRet.getBasicList();
            setSportsmanPhysicalQualityRetValue(basicList, temp);
            map.put("basic", basicList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public SportsmanPhysicalQuality getSportsmanPhysicalQualityDetails(int sportsmanId) {
        return sportsmanPhysicalQualityMapper.getSportsmanPhysicalQualityDetails(sportsmanId);
    }

    @Override
    public void updateSportsmanPhysicalQualityById(SportsmanPhysicalQuality sportsmanPhysicalQuality) {
        sportsmanPhysicalQuality.setId(null);
        sportsmanPhysicalQuality.setCtime(new Date());
        sportsmanPhysicalQualityMapper.insert(sportsmanPhysicalQuality);
    }

}